﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP30.ViewModels
{
    public class ST03CCDManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST03CCDManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;




            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void OnTick(object? sender, EventArgs e)
        {

            ST3ResultOk = CCDPLCToPC_Global.ST3ResultOK;
            ST3ResultNg = CCDPLCToPC_Global.ST3ResultNG;

            if (ST3ResultOk || ST3ResultNg)
            {
                ST3bWorkDone = true;
            }
            else
            {

                ST3bWorkDone = false;
            }
        }

        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST03");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST03View, param);
        }


        private DelegateCommand _CCDAutoTriggerDownCmd;
        public DelegateCommand CCDAutoTriggerDownCmd =>
            _CCDAutoTriggerDownCmd ?? (_CCDAutoTriggerDownCmd = new DelegateCommand(ExecuteCCDAutoTriggerDownCmd));

        void ExecuteCCDAutoTriggerDownCmd()
        {
            CCDPCToPLC_Global.ST3bAutoTrigger = true;
        }


        private DelegateCommand _CCDAutoTriggerUpCmd;
        public DelegateCommand CCDAutoTriggerUpCmd =>
            _CCDAutoTriggerUpCmd ?? (_CCDAutoTriggerUpCmd = new DelegateCommand(ExecuteCCDAutoTriggerUpCmd));

        void ExecuteCCDAutoTriggerUpCmd()
        {
            CCDPCToPLC_Global.ST3bAutoTrigger = false;

        }



        private DelegateCommand _CCDPinBiCommand;
        public DelegateCommand CCDPinBiCommand =>
            _CCDPinBiCommand ?? (_CCDPinBiCommand = new DelegateCommand(ExecuteCCDPinBiCommand));

        void ExecuteCCDPinBiCommand()
        {
            CCDPCToPLC_Global.ST3DisableBT = true;
        }


        private DelegateCommand _CCDUnPinBiCommand;
        public DelegateCommand CCDUnPinBiCommand =>
            _CCDUnPinBiCommand ?? (_CCDUnPinBiCommand = new DelegateCommand(ExecuteCCDUnPinBiCommand));

        void ExecuteCCDUnPinBiCommand()
        {
            CCDPCToPLC_Global.ST3DisableBT = false;

        }


        private DelegateCommand _OpenLightCommand;
        public DelegateCommand OpenLightCommand =>
            _OpenLightCommand ?? (_OpenLightCommand = new DelegateCommand(ExecuteOpenLightCommand));

        void ExecuteOpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = true;

        }

        private DelegateCommand _UnOpenLightCommand;
        public DelegateCommand UnOpenLightCommand =>
            _UnOpenLightCommand ?? (_UnOpenLightCommand = new DelegateCommand(ExecuteUnOpenLightCommand));

        void ExecuteUnOpenLightCommand()
        {
            CCDPCToPLC_Global.ST3LightBT = false;

        }



        #endregion


        #region 属性



        private bool _ST3bWorkDone;
        public bool ST3bWorkDone
        {
            get { return _ST3bWorkDone; }
            set { SetProperty(ref _ST3bWorkDone, value); }
        }

        private bool _ST3ResultOk;
        public bool ST3ResultOk
        {
            get { return _ST3ResultOk; }
            set { SetProperty(ref _ST3ResultOk, value); }
        }
        private bool _ST3ResultNg;
        public bool ST3ResultNg
        {
            get { return _ST3ResultNg; }
            set { SetProperty(ref _ST3ResultNg, value); }
        }



        #endregion
    }


}

